package hms.rooms;

import javax.swing.ListModel;
import javax.swing.event.ListDataListener;

import hms.UserAccountsModule.UserAccount;
import hms.database.DBRowList;
import hms.permissions.Permission;

public class RoomTypeTable extends DBRowList<RoomType> implements ListModel{
	
	public RoomTypeTable(){
		this.fillFromDatabase();
		if(this.isEmpty()) {
			RoomType roomType = addRoomType("Default", 100, 'F', 'F', "Twin", 2);
			RoomType newGuestRoomType = addRoomType("System Only", 0, 'F', 'F', "Twin", 2);
			commitToDatabase();
		}
	}

	@Override
	public void fillFromDatabase() {
		fillFromDatabase(RoomType.class);		
	}
	
	/**
	 * @return the number of room types
	 */
	public int getNumberOfRoomTypes(){
		return this.toArray().length;
	}
	
	/**
	 * Look up Room Type by Room Type Label. Returns null if no room type has that label
	 * or database is empty.
	 */
	public RoomType getRoomTypeByLabel(String i_roomTypeLabel){
		
		RoomType newRoomType = null;
		
		for(RoomType test : this){
			if(test.getRoomTypeLabel().equalsIgnoreCase(i_roomTypeLabel)){
				newRoomType = test;
				break;
			}
		}
		return newRoomType;
	}
	
	public RoomType addRoomType(String roomTypeLabel, int pricePerNight,
			char isSmokingAllowed, char isConnectable, String bedSize, int numberOfBeds){
		
		RoomType newRoomType = new RoomType();
		newRoomType.setRoomTypeLabel(roomTypeLabel);
		newRoomType.setPricePerNight(pricePerNight);
		newRoomType.setIsSmokingAllowed(isSmokingAllowed);
		newRoomType.setIsConnectable(isConnectable);
		newRoomType.setBedSize(bedSize);
		newRoomType.setNumberOfBeds(numberOfBeds);
		this.add(newRoomType);
		return newRoomType;
	}

	@Override
	public void addListDataListener(ListDataListener l) {
		
	}

	@Override
	public Object getElementAt(int index) {
		return get(index);
	}

	@Override
	public int getSize() {
		return size();
	}

	@Override
	public void removeListDataListener(ListDataListener l) {
		
	}
	


}
